package com.example.eldersystem.operatedata.mapper;

import com.example.eldersystem.operatedata.model.Volunteer;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface VolunteerMapper {

    @Insert("insert into volunteer_info(name,gender,phone,id_card,birthday,checkin_date,checkout_date,imgset_dir,profile_photo,description) " +
            "values (#{name},#{gender},#{phone},#{idCard},#{birthday},#{checkinDate},#{checkoutDate},#{imgsetDir},#{profilePhoto},#{description}) ")
    int addVolunteer(Volunteer volunteer);


    @Update("update volunteer_info " +
            "set name=#{name}," +
            "gender=#{gender}," +
            "phone=#{phone}," +
            "id_card=#{idCard}," +
            "birthday=#{birthday}," +
            "checkin_date=#{checkinDate}," +
            "checkout_date=#{checkoutDate}," +
            "imgset_dir=#{imgsetDir}," +
            "profile_photo=#{profilePhoto}," +
            "description=#{description}" +
            "where id = #{id}")
    int updateVolunteer(Volunteer volunteer);

    @Update("update volunteer_info set profile_photo=#{profilePhoto} where id=#{id}")
    int updateProfile(int id,String profilePhoto);

    @Delete("delete from volunteer_info where id = #{id}")
    int deleteVolunteer(int id);

    @Select("select count(*) from volunteer_info")
    int selectVolunteerNum();

    @Select("select * from volunteer_info limit #{from},#{num}")
    @Results(id="select1",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "checkinDate",column = "checkin_date"),
            @Result(property = "checkoutDate",column = "checkout_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "description",column = "description"),
    })
    List<Volunteer> selectVolunteer(int from,int num);

    @Select("select count(*) from volunteer_info where name like concat('%',#{keyName},'%')")
    int selectVolunteerNum2(String keyName);

    @Select("select * from volunteer_info where name like concat('%',#{keyName},'%')")
    @Results(id="select2",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "idCard",column = "id_card"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "checkinDate",column = "checkin_date"),
            @Result(property = "checkoutDate",column = "checkout_date"),
            @Result(property = "imgsetDir",column = "imgset_dir"),
            @Result(property = "profilePhoto",column = "profile_photo"),
            @Result(property = "description",column = "description"),
    })
    List<Volunteer> selectVolunteerByName(String keyName);
}
